<!--
 * @description: 新增提现
 * @Author: latiao
 * @Date: 2021-11-09 09:00:12
 * @LastEditors: vikingShip
 * @LastEditTime: 2021-11-30 15:36:11
-->
<template>
<view class="page">
      <view class="title">提现金额</view>
      <view class="input">
        <input type="digit" style="text-align: center;" maxlength="11" :value="customPrice" @input="inputPrice"
          placeholder="请输入提现金额">
      </view>
      <view class="payNow">
        <view class="payNow__btn" @tap="openMem">立即提现</view>
      </view>
      <view class="record" @click="gotoWithdrawalsRecord">提现记录</view>
    </view>
</template>

<script lang='ts'>
  import {
    Component,
    Vue
  } from 'vue-property-decorator'
  import {
     userMsgUpdate
    } from "@/api/modules/distribution";
  import {
     userIdGet
  } from "@/api/modules/user";

  @Component({})
export default class Withdrawal extends Vue {
  customPrice: number = null;
  timer
  flag

 
throttle(func, wait = 300, immediate = true) {
	if (immediate) {
		if (!this.flag) {
			this.flag = true;
			// 如果是立即执行，则在wait毫秒内开始时执行
			typeof func === 'function' && func();
			this.timer = setTimeout(() => {
				this.flag = false;
			}, wait);
		}
	} else {
		if (!this.flag) {
			this.flag = true
			// 如果是非立即执行，则在wait毫秒内的结束处执行
			this.timer = setTimeout(() => {
				this.flag = false
				typeof func === 'function' && func();
			}, wait);
		}
		
	}
}



   gotoWithdrawalsRecord(){
   uni.navigateTo({
      url: `/subcontract/pages/withdrawalsRecord/withdrawalsRecord`,
    });
   }
    /**
     * @method
     * @description 输入价格
     */
    inputPrice(e) {
      this.setData({
        customPrice: e.detail.value,
      });
      // this.filterRule();
    }
   openMem(){
      const that=this
      this.throttle(
       that.userMsgUpdate,10000
      )
   }
   userMsgUpdate(){
      userIdGet({}).then(id=>{    
     userMsgUpdate({
       accountType:'USER',
       channel:'WECAHT',
       amount:this.customPrice,
       userId:id
     }).then(()=>{
        uni.showToast({
                title: "提现请求已提交，请等待审核",
                icon: "success"
              });
              setTimeout(() => {
              uni.navigateTo({
                url: `/subcontract/pages/balanceValue/balanceValue`,
              });  
              }, 1500);
      
     }).catch(err=>{
       uni.showToast({
                title: err,
                icon: "none"
              });
     })
     })

   }


}
</script>

<style lang="scss" scoped>
 @mixin middle-center {
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .page {
    padding-left: 30rpx;
    padding-right: 30rpx;
    height: 100vh;
    background: #FFF;
  }

  .title {
    font-size: 38rpx;
    padding-top: 40rpx;
    padding-bottom: 40rpx;
  }


  .rechage {
    display: flex;
    justify-content: space-between;
    width: 100%;
    flex-wrap: wrap;

    &__item {
      height: 140rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 20rpx;
      margin-bottom: 30rpx;
      padding-left: 30rpx;
      padding-right: 30rpx;
      border: 1rpx solid #d8dce5;

      &--content {
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        font-size: 38rpx;
      }
    }
  }

  .input {
    height: 100rpx;
    border-radius: 20rpx;
    margin-top: 40rpx;
    @include middle-center;
    background-color: #e5e5e5;
  }

  .payNow {
    display: flex;
    margin-top: 120rpx;
    justify-content: center;
  }

  .payNow__btn {
    width: 600rpx;
    height: 80rpx;
    background: linear-gradient(to right, #EBCC89, #B4893B);
    border-radius: 50rpx;
    color: white;
    font-size: 32rpx;
    @include middle-center;

  }

  .payNow__nbtn {
    background: #888;
  }
  .record{
    margin: 40rpx auto;
    color: rgb(41, 96, 199);
    font-size: 28rpx;
    text-align: center;
  }

</style>